package com.shibaobei.activity.utils;

import org.apache.tomcat.util.http.fileupload.FileUtils;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

/**
 * Created by Administrator on 2020/5/1 0001.
 */
public class UploadFileUtils {

    public static String copy(MultipartFile resource) throws IOException {
        String fileName = resource.getOriginalFilename();
        String filePath = "E:\\IntellijIDEATechnology\\sbb-activity";


        //创建日期目录
        Date date  = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
        String dateStr = sdf.format(date);
        File dateDir = new File(filePath +File.separator+ dateStr+File.separator+ UUID.randomUUID().toString());
        if(!dateDir.exists()){
            dateDir.mkdirs();
        }
        //构造目标文件
        File target = new File(dateDir.getPath() +File.separator + fileName);

        resource.transferTo(target);
        return target.getPath();

    }
}
